﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using RPGX;
using Moq;
using RPGXEngine.Factories;

namespace RPGXEngine.Tests.Unit.Scripting.SystemFunctions
{
    public class SystemFunctionTestBase
    {
        #region Properties

        public Mock<ILogger> MockLogger
        {
            get { return _mockLogger; }
            set { _mockLogger = value; }
        }
        private Mock<ILogger> _mockLogger = new Mock<ILogger>();

        public Mock<IDirectoryRepository> MockDirectoryRepository
        {
            get { return _mockDirectoryRepository; }
            set { _mockDirectoryRepository = value; }
        }
        private Mock<IDirectoryRepository> _mockDirectoryRepository = new Mock<IDirectoryRepository>();

        public ScriptManager ScriptManager
        {
            get { return _scriptManager; }
            set { _scriptManager = value; }
        }
        private ScriptManager _scriptManager = null;

        #endregion

        #region Test Methods

        #endregion

        #region Helper Methods

        public void Load()
        {
            this.SetupMockLogger();
            this.SetupMockDirectoryRepository();

            Game1.Instance = new Game1();
            Game1.Instance.LoadScripting();

            this.ScriptManager = new ScriptManager();
        }

        public void SetupMockLogger()
        {
            LoggerFactory.Set(this.MockLogger.Object);
        }

        public void SetupMockDirectoryRepository()
        {
            this.MockDirectoryRepository.Setup(r => r.GetFiles(It.IsAny<string>(), It.IsAny<string>()))
                                        .Returns(new string [] { });

            DirectoryFactory.Set(this.MockDirectoryRepository.Object);
        }

        public void Shutdown()
        {
            this.ScriptManager.UnLoad();
            this.ScriptManager = null;

            Game1.Instance = null;

            LoggerFactory.Set(null);
        }

        #endregion
    }
}
